﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
using System.Data.SqlClient;

/// <summary>
/// Summary description for clsNOPHI
/// </summary>
public class clsNOPHI
{
	public clsNOPHI()
	{
		//
		// TODO: Add constructor logic here
		//
    }
    public static DataTable Get(string F_MADT, string F_MAHV)
    {
        DataTable dt = new DataTable();
        DatabaseConnect connect = new DatabaseConnect();
        // Tham số
        SqlParameter[] para = new SqlParameter[2];
        para[0] = new SqlParameter("@F_MAHV", F_MAHV);
        para[1] = new SqlParameter("@F_MADT", F_MADT);
        try {
            dt = connect.GetSelectCommand("NOPHI_Get", para);
        }
        catch { }
        return dt;
    }
    //F_TIENNO
    public static decimal getF_TIENNO(string F_MADT, string F_MAHV)
    {
        decimal rs = 0;
        DataTable dt = new DataTable();
        dt = Get(F_MADT, F_MAHV);
        if (dt.Rows.Count > 0)
        {
            try {
                rs = decimal.Parse(dt.Rows[0]["F_TIENNO"].ToString());
            }
            catch { }
        }
        return rs;
    }
    #region Update
    public static string Update(string F_MADT, string F_MAHV, decimal F_TIENNO, string F_GHICHU)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham số
        SqlParameter[] para = new SqlParameter[4];
        para[0] = new SqlParameter("@F_MAHV", F_MAHV);
        para[1] = new SqlParameter("@F_MADT", F_MADT);
        para[2] = new SqlParameter("@F_TIENNO", F_TIENNO);
        para[3] = new SqlParameter("@F_GHICHU", F_GHICHU);
        try
        {
            connect.ExecuteQuery("NOPHI_Update", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    #endregion

    #region Resume
    public static string Resume(string F_MADT, string F_MAHV, decimal F_TIENNO)
    {
        DatabaseConnect connect = new DatabaseConnect();
        SqlParameter[] para = new SqlParameter[3];
        para[0] = new SqlParameter("@F_MAHV", F_MAHV);
        para[1] = new SqlParameter("@F_MADT", F_MADT);
        para[2] = new SqlParameter("@F_TIENNO", F_TIENNO);
        try
        {
            connect.ExecuteQuery("NOPHI_Resume", para);
            return "OK";
        }
        catch 
        {
            return "ERR";
        }
    }
    #endregion

    public static string Insert(string F_MADT, string F_MAHV, decimal F_TIENNO)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham số
        SqlParameter[] para = new SqlParameter[3];
        para[0] = new SqlParameter("@F_MAHV", F_MAHV);
        para[1] = new SqlParameter("@F_MADT", F_MADT);
        para[2] = new SqlParameter("@F_TIENNO", F_TIENNO);        
        try
        {
            connect.ExecuteQuery("NOPHI_Insert", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
    public static string Insert_HVHL(string F_MADT, string F_MAHV, decimal F_TIENNO)
    {
        DatabaseConnect connect = new DatabaseConnect();
        // Tham số
        SqlParameter[] para = new SqlParameter[3];
        para[0] = new SqlParameter("@F_MAHV", F_MAHV);
        para[1] = new SqlParameter("@F_MADT", F_MADT);
        para[2] = new SqlParameter("@F_TIENNO", F_TIENNO);
        try
        {
            connect.ExecuteQuery("NOPHI_Insert_HVHL", para);
            return "OK";
        }
        catch
        {
            return "ERR";
        }
    }
}